﻿using Admin2020.Service.Log;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;

namespace Admin2020.Service.Filters
{
    public class HttpGlobalExceptionFilter : IExceptionFilter
    {
        private readonly Interface.ILogger _logger;

        public HttpGlobalExceptionFilter(Interface.ILogger logger)
        {
            _logger = logger;
        }


        public void OnException(ExceptionContext context)
        {
            //捕获全局异常，记入数据库日志
            _logger.Error(context.Exception.Message, context.Exception);
            context.ExceptionHandled = true;
        }
    }
}
